home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Container / Sources / View.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  11.4 KB  |  405 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                View.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef VIEW_H
  13. #include "View.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef DEFINES_K
  21. #include "Defines.k"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. #ifndef FRAME_H
  29. #include "Frame.h"
  30. #endif
  31.  
  32. #ifndef SELECT_H
  33. #include "Select.h"
  34. #endif
  35.  
  36. #ifndef COMMANDS_H
  37. #include "Commands.h"
  38. #endif
  39.  
  40. #ifndef PROXY_H
  41. #include "Proxy.h"
  42. #endif
  43.  
  44. // ----- Framework Layer -----
  45.  
  46. #ifndef FWUTIL_H
  47. #include "FWUtil.h"
  48. #endif
  49.  
  50. #ifndef FWEVEDEF_H
  51. #include "FWEveDef.h"
  52. #endif
  53.  
  54. #ifndef FWPRESEN_H
  55. #include "FWPresen.h"
  56. #endif
  57.  
  58. #ifndef FWSCROLR_H
  59. #include "FWScrolr.h"
  60. #endif
  61.  
  62. #ifndef FWSCLBAR_H
  63. #include "FWSclBar.h"
  64. #endif
  65.  
  66. #ifndef FWGROWBX_H
  67. #include "FWGrowBx.h"
  68. #endif
  69.  
  70. #ifndef FWCONTXT_H
  71. #include "FWContxt.h"
  72. #endif
  73.  
  74. #ifndef FWCLPCMD_H
  75. #include "FWClpCmd.h"
  76. #endif
  77.  
  78. #ifndef FWFCTCLP_H
  79. #include "FWFctClp.h"
  80. #endif
  81.  
  82. // ----- OS Layer -----
  83.  
  84. #ifndef FWMENU_H
  85. #include "FWMenu.h"
  86. #endif
  87.  
  88. #ifndef FWRECSHP_H
  89. #include "FWRecShp.h"
  90. #endif
  91.  
  92. #ifndef FWCURSOR_H
  93. #include "FWCursor.h"
  94. #endif
  95.  
  96. #ifndef FWEVENT_H
  97. #include "FWEvent.h"
  98. #endif
  99.  
  100. #ifndef FWODGEOM_H
  101. #include "FWODGeom.h"
  102. #endif
  103.  
  104. // ----- OpenDoc Includes -----
  105.  
  106. #ifndef SOM_Module_OpenDoc_Commands_defined
  107. #include <CmdDefs.xh>
  108. #endif
  109.  
  110. #ifndef SOM_Module_OpenDoc_StdProps_defined
  111. #include <StdProps.xh>
  112. #endif
  113.  
  114. //========================================================================================
  115. // Runtime Information
  116. //========================================================================================
  117.  
  118. #ifdef FW_BUILD_MAC
  119. #pragma segment odfcontainer
  120. #endif
  121.  
  122. //========================================================================================
  123. // CContainerView
  124. //========================================================================================
  125.  
  126. FW_DEFINE_CLASS_M1(CContainerView, FW_CSuperView)
  127.  
  128. // IMPORTANT: the constant below must match the resource label for RContainerView in views.fr
  129. const FW_ClassTypeConstant LContainerView = FW_TYPE_CONSTANT('c','t','v','w');
  130. FW_REGISTER_ARCHIVABLE_CLASS(LContainerView, CContainerView, CContainerView::Create, FW_CView::Read, CContainerView::Destroy, FW_CView::Write)
  131.  
  132. //----------------------------------------------------------------------------------------
  133. // CContainerView::CContainerView
  134. //----------------------------------------------------------------------------------------
  135.  
  136. CContainerView::CContainerView(Environment* ev, CContainerFrame* frame, FW_CRect& bounds, 
  137.                                     FW_CPoint& extent, CContainerPart* part) :
  138.     FW_CSuperView(ev, frame, bounds, kContainerViewID, extent, FW_kXYScrolling),
  139.     fContainerPart(part),
  140.     fContainerFrame(frame),
  141.     fPartContent(part->GetPartContent())
  142. {    
  143. }
  144.  
  145. CContainerView::CContainerView(Environment* ev) :
  146.     FW_CSuperView(ev),
  147.     fContainerPart(NULL),
  148.     fContainerFrame(NULL),
  149.     fPartContent(NULL)
  150. {    
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154. // CContainerView::~CContainerView
  155. //----------------------------------------------------------------------------------------
  156.  
  157. CContainerView::~CContainerView()
  158. {
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. // CContainerView::Draw
  163. //----------------------------------------------------------------------------------------
  164.  
  165. void CContainerView::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  166. {
  167.     // Render inside the content view
  168.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  169.     FW_CRect invalidRect;
  170.     vc.GetClipRect(invalidRect);
  171.  
  172.     FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_CColor(56000, 56000, 65535));
  173.  
  174.  
  175.     // ----- Render every proxy -----
  176.     //    Note: like ODFDraw I don't let OpenDoc draws embedded facets because I want to
  177.     //    manage z-ordering myself
  178.     CContentProxyIterator ite(fPartContent);
  179.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  180.     {
  181.         FW_CRect updateBox = proxy->GetBounds(ev);
  182.         if (invalidRect.IsIntersecting(updateBox))
  183.             proxy->Render(ev, odFacet, vc);
  184.     }
  185.  
  186.     // ----- Render selection handles -----
  187.     // Do not render handles for print / print preview
  188.     if (GetFrame(ev)->HasSelectionFocus(ev) && odFacet->GetCanvas(ev)->IsDynamic(ev))    
  189.     {    
  190.         fContainerFrame->GetSelection(ev)->RenderSelectionHandles(ev, vc);
  191.     }
  192. }
  193.  
  194. //----------------------------------------------------------------------------------------
  195. // CContainerView::AdjustToNewLayout
  196. //----------------------------------------------------------------------------------------
  197.  
  198. void CContainerView::AdjustToNewLayout(Environment *ev, const FW_CPoint& oldExtent, 
  199.                                         const FW_CPoint& newExtent, FW_Boolean refresh)
  200. {
  201. FW_UNUSED(oldExtent);
  202. FW_UNUSED(newExtent);
  203.  
  204.     fContainerFrame->AdjustContentViewSize(ev, refresh);
  205. }
  206.     
  207. //----------------------------------------------------------------------------------------
  208. // CContainerView::AdjustCursor
  209. //----------------------------------------------------------------------------------------
  210.  
  211. FW_Boolean CContainerView::AdjustCursor(Environment* ev, ODFacet* facet, const FW_CPoint& where)
  212. {
  213.     if (fContainerFrame->GetWindow(ev)->IsActive(ev) == false)
  214.     {
  215.         // Keep the arrow cursor in non-active windows
  216.         FW_gArrowCursor.Select();
  217.     }
  218.     // Must call the base class first to adjust cursor in active border of embedded frames
  219.     else if (FW_CView::AdjustCursor(ev, facet, where) == false)
  220.     {
  221.         // convert mouse position to content space for WhichProxy
  222.         FW_CPoint mouse(where);
  223.         FrameToViewContent(ev, mouse);
  224.         FW_CViewContext vc(ev, this, facet); 
  225.  
  226.         // Check if mouse is over the selection's handle first
  227.         short proxyHandle;
  228.         CContainerSelection* selection = fContainerFrame->GetSelection(ev);
  229.         
  230.         if (selection->WhichHandle(ev, vc, mouse, proxyHandle))
  231.         {
  232.             switch(proxyHandle)
  233.             {
  234.                 case kInTopLeftCorner:
  235.                 case kInBottomRightCorner:
  236.                     FW_gSizeNWSECursor.Select();
  237.                     break;
  238.                 case kInTopRightCorner:
  239.                 case kInBottomLeftCorner:
  240.                     FW_gSizeNESWCursor.Select();
  241.                     break;
  242.                 case kInTopMiddle:
  243.                 case kInBottomMiddle:
  244.                     FW_gSizeNSCursor.Select();
  245.                     break;
  246.                 case kInLeftMiddle:
  247.                 case kInRightMiddle:
  248.                     FW_gSizeWECursor.Select();
  249.                     break;
  250.             }
  251.         }
  252.         
  253.         // Else use the hand cursor over a proxy to show dragging operation
  254.         else if (fContainerPart->WhichProxy(ev, vc, mouse, TRUE))
  255.             FW_gOpenHandCursor.Select();
  256.  
  257.         // Else use the cross hair cursor to show selection operation
  258.         else
  259.             FW_gCrossHairCursor.Select();
  260.     }
  261.     return true;
  262. }
  263.  
  264. //----------------------------------------------------------------------------------------
  265. //    CContainerView::DoVirtualKey
  266. //----------------------------------------------------------------------------------------
  267.  
  268. FW_Boolean CContainerView::DoVirtualKey(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
  269. {    
  270.     FW_Boolean wasHandled = FALSE;
  271.     
  272.     switch (theVirtualKeyEvent.GetKeyCode(ev))
  273.     {
  274.         case FW_kVKBackspace:
  275.         case FW_kVKClear:
  276.             if (!fContainerFrame->GetSelection(ev)->IsEmpty(ev))
  277.             {
  278.                 FW_CClipboardCommand* cmd =    GetFrame(ev)->NewClipboardCommand(ev, kODCommandClear);
  279.                 if (cmd)
  280.                 {
  281.                     cmd->Execute(ev);
  282.                     wasHandled = TRUE;
  283.                 }
  284.             }
  285.             break;
  286.     }
  287.  
  288.     return wasHandled;
  289. }
  290.  
  291. //----------------------------------------------------------------------------------------
  292. // CContainerView::WantsToBeTarget
  293. //----------------------------------------------------------------------------------------
  294.  
  295. FW_Boolean CContainerView::WantsToBeTarget(Environment* ev)
  296. {
  297.     return TRUE;
  298. }
  299.  
  300. //----------------------------------------------------------------------------------------
  301. // CContainerView::DoMouseDown
  302. //----------------------------------------------------------------------------------------
  303.  
  304. FW_Boolean CContainerView::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  305. {
  306.     FW_Boolean result = TRUE;
  307.     
  308.     ODFacet* theFacet = theMouseEvent.GetFacet(ev);
  309.     CContainerSelection* selection = fContainerFrame->GetSelection(ev);
  310.     
  311.     if (selection->IsMouseInDraggableItem(ev, fContainerFrame, theMouseEvent, FALSE))
  312.     {
  313.         FW_gClosedHandCursor.Select();
  314.         result = fContainerFrame->Drag(ev, theMouseEvent);
  315.     }
  316.     else if (!selection->Resize(ev, theMouseEvent))
  317.     {
  318.         selection->SelectWithRectangle(ev, theMouseEvent);
  319.     }
  320.                         
  321.     return result;
  322. }
  323.  
  324. //----------------------------------------------------------------------------------------
  325. // CContainerView::SizeChanged
  326. //----------------------------------------------------------------------------------------
  327. //    My content view size has changed so I need to clip my embedded facets. It's better to do it
  328. //    here than in CContainerFrame::FrameShapeChanged because my frame shape can be changing but
  329. //    my bounds may not.
  330.  
  331. void CContainerView::SizeChanged(Environment* ev, const FW_CPoint& oldSize)
  332. {
  333.     FW_CSuperView::SizeChanged(ev, oldSize);
  334.     
  335.     FW_CFacetClipper facetClipper(ev, fContainerPart);
  336.     facetClipper.Clip(ev, fContainerFrame, NULL);
  337. }
  338.  
  339. //----------------------------------------------------------------------------------------
  340. //    CContainerView::Create
  341. //----------------------------------------------------------------------------------------
  342.  
  343. void* CContainerView::Create(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  344. {
  345. FW_UNUSED(stream);
  346. FW_UNUSED(type);
  347.     FW_SOMEnvironment ev;
  348.     
  349.     // Call minimal constructor.  Data fields will be initialized in InitializeFromStream
  350.     return new CContainerView(ev);
  351. }
  352.  
  353. //----------------------------------------------------------------------------------------
  354. //    CContainerView::Destroy
  355. //----------------------------------------------------------------------------------------
  356.  
  357. void CContainerView::Destroy(void* object, FW_ClassTypeConstant type)
  358. {
  359. FW_UNUSED(type);
  360.     CContainerView* self = (CContainerView*) object;
  361.     delete self;
  362. }
  363.  
  364. //----------------------------------------------------------------------------------------
  365. //    CContainerView::Flatten
  366. //----------------------------------------------------------------------------------------
  367. // This method is required to handle custom resource fields added to the base type
  368.  
  369. void CContainerView::Flatten(Environment* ev, FW_CWritableStream& archive) const
  370. {
  371.     FW_CSuperView::Flatten(ev, archive);
  372.     
  373.     // Container doesn't have any custom fields to stream out
  374. }
  375.  
  376.  
  377. //----------------------------------------------------------------------------------------
  378. //    CContainerView::InitializeFromStream
  379. //----------------------------------------------------------------------------------------
  380. // This method is required to handle custom resource fields added to the base type
  381. // and to initialize other class fields not initialized in the minimal ctor.
  382.  
  383. void CContainerView::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
  384. {
  385.     // Read-in the base resource first
  386.     FW_CSuperView::InitializeFromStream(ev, stream);
  387.     
  388.     // Get a pointer to the frame which was pre-registered
  389.     FW_OObjectRegistry*    registry = stream.GetRegistry();
  390.     FW_CFrame* frame = (FW_CFrame*) registry->LookupByID(ev, FW_kPreregisteredFrameObject);
  391.     FW_ASSERT(frame != NULL);
  392.     
  393.     // Set the fContainerFrame, fContainerPart & fPartContent fields
  394.     fContainerFrame = FW_DYNAMIC_CAST(CContainerFrame, frame);
  395.     FW_ASSERT(fContainerFrame != NULL);
  396.     
  397.     FW_CEmbeddingPart* part = fContainerFrame->GetPart(ev);
  398.     fContainerPart = FW_DYNAMIC_CAST(CContainerPart, part);
  399.     FW_ASSERT(fContainerPart != NULL);
  400.  
  401.     fPartContent = fContainerPart->GetPartContent();
  402.     FW_ASSERT(fPartContent != NULL);
  403. }
  404.  
  405.